package com.zf.apartment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zf.common.annotation.Log;
import com.zf.common.core.controller.BaseController;
import com.zf.common.core.domain.AjaxResult;
import com.zf.common.enums.BusinessType;
import com.zf.apartment.domain.PropertyData;
import com.zf.apartment.service.IPropertyDataService;
import com.zf.common.utils.poi.ExcelUtil;
import com.zf.common.core.page.TableDataInfo;

/**
 * 属性数据Controller
 * 
 * @author rxf
 * @date 2024-10-08
 */
@RestController
@RequestMapping("/apartment/data")
public class PropertyDataController extends BaseController
{
    @Autowired
    private IPropertyDataService propertyDataService;

    /**
     * 查询属性数据列表
     */
    @PreAuthorize("@ss.hasPermi('apartment:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(PropertyData propertyData)
    {
        startPage();
        List<PropertyData> list = propertyDataService.selectPropertyDataList(propertyData);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('apartment:data:list')")
    @GetMapping("/find")
    public TableDataInfo find(PropertyData propertyData)
    {
        startPage();
        List<PropertyData> list = propertyDataService.findPropertyDataList(propertyData);
        return getDataTable(list);
    }

    /**
     * 导出属性数据列表
     */
    @PreAuthorize("@ss.hasPermi('apartment:data:export')")
    @Log(title = "属性数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PropertyData propertyData)
    {
        List<PropertyData> list = propertyDataService.selectPropertyDataList(propertyData);
        ExcelUtil<PropertyData> util = new ExcelUtil<PropertyData>(PropertyData.class);
        util.exportExcel(response, list, "属性数据数据");
    }

    /**
     * 获取属性数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('apartment:data:query')")
    @GetMapping(value = "/{propertyDataId}")
    public AjaxResult getInfo(@PathVariable("propertyDataId") Long propertyDataId)
    {
        return success(propertyDataService.selectPropertyDataByPropertyDataId(propertyDataId));
    }

    /**
     * 新增属性数据
     */
    @PreAuthorize("@ss.hasPermi('apartment:data:add')")
    @Log(title = "属性数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PropertyData propertyData)
    {
        return toAjax(propertyDataService.insertPropertyData(propertyData));
    }

    /**
     * 修改属性数据
     */
    @PreAuthorize("@ss.hasPermi('apartment:data:edit')")
    @Log(title = "属性数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PropertyData propertyData)
    {
        return toAjax(propertyDataService.updatePropertyData(propertyData));
    }

    /**
     * 删除属性数据
     */
    @PreAuthorize("@ss.hasPermi('apartment:data:remove')")
    @Log(title = "属性数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{propertyDataIds}")
    public AjaxResult remove(@PathVariable Long[] propertyDataIds)
    {
        return toAjax(propertyDataService.deletePropertyDataByPropertyDataIds(propertyDataIds));
    }
}
